﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace Galaktika.BI.Silverlight.Controls.OLAP.Descriptions
{
    [XmlRoot(Namespace=Common.Namespace)]
    public class CellSetDescription
    {
        string m_CubeName = String.Empty;
        public string CubeName
        {
            get { return m_CubeName; }
            set { m_CubeName = value; }
        }

        String m_ConnectionString = String.Empty;
        public String ConnectionString
        {
            get { return m_ConnectionString; }
            set { m_ConnectionString = value; }
        }


        List<AxisDescription> m_Axes = null;
        /// <summary>
        /// Оси
        /// </summary>
        public List<AxisDescription> Axes
        {
            get
            {
                if (m_Axes == null)
                    m_Axes = new List<AxisDescription>();
                return m_Axes;
            }
            set { m_Axes = value; }
        }

        List<CellDescription> m_Cells = null;
        /// <summary>
        /// Ячейки
        /// </summary>
        public List<CellDescription> Cells
        {
            get
            {
                if (m_Cells == null)
                    m_Cells = new List<CellDescription>();
                return m_Cells;
            }
            set { m_Cells = value; }
        }

        // Пока информация о FilterAxis не нужна
        //AxisDescription m_FilterAxis = null;
        //public AxisDescription FilterAxis
        //{
        //    get { return m_FilterAxis; }
        //    set { m_FilterAxis = value; }
        //}

        public CellDescription GetCellDescription(int col, int row)
        {
            if (col >= 0 && row >= 0)
            {
                foreach (CellDescription cell in Cells)
                {
                    if (cell.Axis0_Coord == col &&
                        cell.Axis1_Coord == row)
                    {
                        return cell;
                    }
                }
            }
            return null;
        }

        public static CellSetDescription Parse(string xml)
        {
            return Galaktika.BI.Silverlight.XmlUtility.XmlStr2Obj<CellSetDescription>(xml);
        }
    }
}
